package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by AD on 2016/5/12.
 */
@HttpInlet(Conn.INLET_GET_SPECIAL_SALE_DETAIL)
public class GetSpecialSaleList extends JTAsyGet<GetSpecialSaleList.Info> {

    public String token = JTApplication.jtPreferences.readToken();

    public String id;

    public GetSpecialSaleList(AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {
        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        JSONObject body = apiTYF.optJSONObject("body");

        info.logourl = body.optString("columnpic");

        JSONArray specialSaleList = body.optJSONArray("columndetail");

        if (specialSaleList != null) {

            for (int i = 0; i < specialSaleList.length(); i++) {

                JSONObject object_gs = specialSaleList.optJSONObject(i);

                SSList ssItem = new SSList();

                ssItem.ID = object_gs.optString("BUSINESS_ID");

                ssItem.TITLE = object_gs.optString("TITLE");

                ssItem.DESCRIBE = object_gs.optString("DES");

                ssItem.PIC = object_gs.optString("PIC");

                info.ssLists.add(ssItem);

            }

        }

        return info;
    }

    public static class Info {

        public String msg;

        public String logourl;

        public List<SSList> ssLists = new ArrayList<>();

    }

    public static class SSList implements Serializable {

        public String ID, TITLE, DESCRIBE, PIC;

    }
}
